using System;
using System.Collections;
using UnityEngine;

public class tk2dStretch : MonoBehaviour
{
	private void Start()
	{
		base.StartCoroutine(this.CoStretchScale());
	}

	private IEnumerator CoStretchScale()
	{
		for (int i = 0; i < 10; i++)
		{
			if (this.sizeX != this.cam.ScreenExtents.width)
			{
				this.StretchScale();
				this.sizeX = this.cam.ScreenExtents.width;
			}
			yield return new WaitForSeconds(0.05f);
		}
		yield break;
	}

	public void StretchScale()
	{
		base.gameObject.transform.localScale = Vector3.one;
		Bounds renderBound = this.GetRenderBound(base.gameObject);
		Rect screenExtents = this.cam.ScreenExtents;
		float num = renderBound.size.x / renderBound.size.y;
		float num2 = screenExtents.width / screenExtents.height;
		if (num > num2)
		{
			base.transform.localScale = base.transform.localScale * (screenExtents.height / renderBound.size.y);
		}
		else
		{
			base.transform.localScale = base.transform.localScale * (screenExtents.width / renderBound.size.x);
		}
	}

	private Bounds GetRenderBound(GameObject go)
	{
		Bounds result = new Bounds(go.transform.position, Vector3.zero);
		foreach (Renderer renderer in go.GetComponentsInChildren<Renderer>())
		{
			result.Encapsulate(renderer.bounds);
		}
		return result;
	}

	public tk2dCamera cam;

	private float sizeX;
}
